package com.laoniu.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisService {

    @Autowired
    private RedisTemplate redisTemplate;

    public void set(String key, String value){
        redisTemplate.opsForValue().set(key,value);
    }

    public String get(String key){
       return (String) redisTemplate.opsForValue().get(key);
    }

    public void set(String key, String value, Long timeout){
        redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
    }

    public void delKey(String key){
        redisTemplate.delete(key);
    }
}
